package io.sage.modules.readsenseapi.controller;

import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageInfo;
import io.sage.common.validator.ValidatorUtils;
import io.sage.modules.flow.service.FlowCustomersService;
import io.sage.modules.readsenseapi.entity.BFlowCustomers;
import io.sage.modules.readsenseapi.vo.FlowCustomersVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.sage.common.utils.R;


/**
 * @author zhang
 * @email ${email}
 * @date 2019-08-08 14:25:25
 */
@RestController
@RequestMapping("flow/bflowcustomers")
public class BFlowCustomersController {
    @Autowired
    private FlowCustomersService FlowCustomersService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("flow:bflowcustomers:list")
    public R list(@RequestParam Map<String, Object> params) {

        List<BFlowCustomers> bFlowCustomers = FlowCustomersService.selectFlowCustomersList(null);
        PageInfo<BFlowCustomers> pageInfo = new PageInfo<BFlowCustomers>(bFlowCustomers);// 传入list就可以了
        return R.ok().put("bFlowCustomers", pageInfo);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("flow:bflowcustomers:info")
    public R info(@PathVariable("id") String id) {
        BFlowCustomers bFlowCustomers = FlowCustomersService.selectByPrimaryKey(id);
        return R.ok().put("bFlowCustomers", bFlowCustomers);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("flow:bflowcustomers:save")
    public R save(@RequestBody FlowCustomersVo flowCustomersVo) {
        int insert = FlowCustomersService.insert(flowCustomersVo);
        if(insert>0){
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("flow:bflowcustomers:update")
    public R update(@RequestBody FlowCustomersVo flowCustomersVo) {
        int upd = FlowCustomersService.updateByPrimaryKeySelective(flowCustomersVo);
        if(upd>0){
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("flow:bflowcustomers:delete")
    public R delete(@RequestBody String[] ids) {
        int del = FlowCustomersService.deleteBatchIds(ids);
        if(del>0){
            return R.ok();
        }
        return R.error();
    }

}
